package modellayer;
import java.util.ArrayList;

/**
 * Write a description of class Salg here.
 * 
 * @author (Jonas, Dani og Peter) 
 * @version (09-12-2014)
 */
public class Salg
{
    private double total;
    private String id;
    private String dato;
    private Kunde kunde;
    private ArrayList<DelSalg> delsalg;
    private Ordre ordre;
    private boolean state;

    /**
     * Constructor for objects of class Salg
     */
    public Salg(String id, String dato)
    {
        this.id = id;
        this.state = false;
        this.dato = dato;
        delsalg = new ArrayList<DelSalg>();
    }
    
    /**
     * Constructor for objects of class Salg.
     */
    public Salg(String id, String dato, boolean levering)
    {
        this.id = id;
        this.state = false; // has Salg completed?
        this.dato = dato;
        delsalg = new ArrayList<DelSalg>();
        this.ordre = new Ordre(levering);
    }

    /**
     * Calculates the total amount of money to be paid.
     */
    private void udregnTotal()
    {
        int size = this.delsalg.size();
        double amount = 0;
        for(int i = 0; i < size && !delsalg.isEmpty(); i++)
        {
            amount += delsalg.get(i).getDelTotal();
        }
        this.total = amount;
    }
    
    /**
     * Acessor method for attriute id.
     */
    public String getID()
    {
        return id;
    }
    
    /**
     * Mutator method for attriute id.
     */
    public void setID(String ID)
    {
        this.id = id;
    }
    
    /**
     * Acessor method for attriute dato.
     */
    public String getDato()
    {
        return dato;
    }
    
    /**
     * Mutator method for attriute dato.
     */
    public void setDato(String dato)
    {
        this.dato = dato;
    }
    
    /**
     * Mutator method for attriute state.
     */
    public void setState(boolean state)
    {
        this.state = state;
    }
    
    /**
     * Acessor method for attriute adresse.
     */
    public boolean getState()
    {
        return this.state;
    }
    
    /**
     * Adds a delsalg to the arraylist delsalg.
     * 
     * @param newDelsalg a DelSalg to be added to the arraylist.
     */
    public void addDelSalg(DelSalg newDelsalg)
    {
        delsalg.add(newDelsalg);
    }
    
    /**
     * Mutator method for attriute kunde.
     */
    public void setKunde(Kunde kunde)
    {
        this.kunde = kunde;
    }
    
    /**
     * Acessor method for attriute delsalg.
     */
    public ArrayList<DelSalg> getDelSalg()
    {
        return delsalg;
    }
    
    /**
     * Mutator method for attriute levering.
     */
    public void setOrdre(boolean levering)
    {
        this.ordre = new Ordre(levering);
    }
    
    /**
     * Acessor method for attriute adresse.
     */
    public Ordre getOrdre()
    {
        return this.ordre;
    }
    
    /**
     * Mutator method for attriute total.
     */
    public void setTotal(int total)
    {
        this.total = total;
    }
    
    /**
     * Acessor method for attriute total.
     */
    public double getTotal()
    {   
        udregnTotal();
        return this.total;
    }
    
}
